<template>
  <div class="siede_menu_wrapper">
    <slot name="logo"></slot>
    <el-menu :default-active="this.$route.path" class="el-menu-vertical-demo" :router="true" @open="handleOpen" @close="handleClose">
      <template v-for="(item, index) in menuList">
        <el-menu-item v-if="!item.children" :key="`menu_item_${index}`" :index="`/${item.name}`">
          <i :class="item.icon"></i>
          <span slot="title">{{ item.meta.title }}</span>
        </el-menu-item>
        <el-submenu v-else :key="`menu_item_${index}`" :index="`/${item.name}`">
          <template slot="title">
            <i :class="item.icon"></i>
            <span>{{ item.meta.title }}</span>
          </template>
          <template v-for="(itm, idx) in item.children">
            <el-menu-item :key="`menu_itm_${idx}`" :index="`/${item.name}/${itm.name}`">
              <i class="el-icon-menu"></i>
              <span slot="title">{{ item.meta.title }}</span>
            </el-menu-item>
          </template>
        </el-submenu>
      </template>
    </el-menu>
  </div>
</template>

<script>
export default {
  name: "SideMenu",
  props: {
    menuList: {
      type: Array,
      default: () => []
    }
  },
  mounted () {
    // console.log(this.menuList)
  },
  methods: {
    handleOpen(key, keyPath) {
      // console.log(key, keyPath);
    },
    handleClose(key, keyPath) {
      // console.log(key, keyPath);
    }
  }
}
</script>

<style lang="less" scoped>
  @import "./SideMenu.less";
</style>
